package com.lhj.reggie.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.lhj.reggie.common.R;
import com.lhj.reggie.entity.Employee;
import com.lhj.reggie.service.EmployeeService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * 员工管理
 */
@Slf4j
@RestController
@RequestMapping("/employee")
public class EmployeeController {
    @Resource
    private EmployeeService employeeService;

    /**
     * 员工登录功能
     * @param request
     * @param employee
     * @return
     */
    @PostMapping("/login")
    public R<Employee> login(HttpServletRequest request,@RequestBody Employee employee ){
        return employeeService.login(request,employee);
    }

    /**
     * 员工登出功能
     * @param request
     * @return
     */
    @PostMapping("/logout")
    public R<String> logout(HttpServletRequest request){
        return employeeService.logout(request);
    }

    /**
     * 新增员工功能
     * @param employee
     * @return
     */
    @PostMapping
    public R<String> save(HttpServletRequest request,@RequestBody Employee employee){
        return employeeService.insert(request,employee);
    }

    /**
     * 员工分页查询功能
     * @param page
     * @param pageSize
     * @param name
     * @return
     */
   @GetMapping("/page")
    public R<Page> page(int page,int pageSize,String name){
        return employeeService.page(page,pageSize,name);
   }

    /**
     * 根据员工id修改信息
     * @param request
     * @param employee
     * @return
     */
   @PutMapping
    public R<String> update(HttpServletRequest request,@RequestBody Employee employee){
       return employeeService.update(request,employee);
   }

    /**
     * 根据员工id查询信息
     * @param id
     * @return
     */
   @GetMapping("/{id}")
   public R<Employee> get(@PathVariable Long id){
       return employeeService.getById(id);
   }
}
